package cn.com.aiton.common.utils;

import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by Administrator on 2016/4/15.
 */
public class MD5Utils {

    private static final Logger LOG = LoggerFactory.getLogger(MD5Utils.class);
    /**
     * 密码加密工具
     *
     * @param str
     * @return
     */
    public static String StringMD5(String str) {
        String encrypt = null;
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            byte[] output = digest.digest(str.getBytes());
            encrypt = Base64.encodeBase64String(output);
        } catch (NoSuchAlgorithmException e) {
            //todo: To change body of catch statement use File | Settings | File Templates.
            LOG.error(e.getMessage(),e);
        }
        return encrypt;
    }

}
